package com.cskaoyan.wordmemorize.controller.admin;

import com.cskaoyan.wordmemorize.common.result.Result;
import com.cskaoyan.wordmemorize.dto.admin.DeleteBookCategoryOperateDTO;
import com.cskaoyan.wordmemorize.dto.admin.PageDTO;
import com.cskaoyan.wordmemorize.dto.admin.VocCategoryDTO;
import com.cskaoyan.wordmemorize.request.BatchDeleteCommand;
import com.cskaoyan.wordmemorize.request.PageRequest;
import com.cskaoyan.wordmemorize.request.VocCategoryCommand;
import com.cskaoyan.wordmemorize.service.VocCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 单词书籍类目管理控制器
 */
@RestController
@RequestMapping("/admin/voc")
public class VocCategoryController {

    @Autowired
    private VocCategoryService vocCategoryService;

    /**
     * 分页获取书籍类目(后端-物料管理-书记类目管理)
     *
     * @param pageRequest 分页查询请求
     * @return 分页查询结果
     */
    @GetMapping("/category/list")
    public Result<PageDTO<VocCategoryDTO>> getBookCategories(PageRequest pageRequest) {
        PageDTO<VocCategoryDTO> pageDTO = vocCategoryService.getBookCategories(pageRequest);
        return Result.ok(pageDTO);
    }

    /**
     * 获取指定的书籍类目(后端-物料管理-书记类目管理)
     *
     * @param categoryId 类目ID
     * @return 类目详情
     */
    @GetMapping("/category")
    public Result<VocCategoryDTO> getBookCategory(@RequestParam Long categoryId) {
        VocCategoryDTO categoryDTO = vocCategoryService.getBookCategory(categoryId);
        return Result.ok(categoryDTO);
    }

    /**
     * 添加书籍类目(后端-物料管理-书记类目管理)
     *
     * @param command 类目请求体对象
     * @return 新增类目的ID
     */
    @PostMapping("/category")
    public Result<Long> addBookCategory(@RequestBody VocCategoryCommand command) {
        Long categoryId = vocCategoryService.addBookCategory(command);
        return Result.ok(categoryId);
    }

    /**
     * 更新书籍类目(后端-物料管理-书记类目管理)
     *
     * @param command 类目请求体对象
     * @return 空结果
     */
    @PutMapping("/category")
    public Result<Void> updateBookCategory(@RequestBody VocCategoryCommand command) {
        vocCategoryService.updateBookCategory(command);
        return Result.ok();
    }

    /**
     * 删除指定书籍类目(后端-物料管理-书记类目管理)
     *
     * @param categoryId 类目ID
     * @return 删除操作日志
     */
    @DeleteMapping("/category/{categoryId}")
    public Result<DeleteBookCategoryOperateDTO> deleteBookCategory(@PathVariable Long categoryId) {
        DeleteBookCategoryOperateDTO operateDTO = vocCategoryService.deleteBookCategory(categoryId);
        return Result.ok(operateDTO);
    }

    /**
     * 批量删除选中的书籍类目(后端-物料管理-书记类目管理)
     *
     * @param command 批量删除请求体对象
     * @return 删除操作日志列表
     */
    @DeleteMapping("/categories")
    public Result<List<DeleteBookCategoryOperateDTO>> deleteBookCategories(@RequestBody BatchDeleteCommand command) {
        List<DeleteBookCategoryOperateDTO> operateDTOList = vocCategoryService.deleteBookCategories(command);
        return Result.ok(operateDTOList);
    }
}
